layui.config({
    base: '/static/js/lib/',
    version:new Date().getTime()
}).use(['element', 'layer', 'navbar'], function(){
    $ = layui.jquery;
    element = layui.element;
    var navbar=layui.navbar();
    var navbarIndex=1;
    navbar.set({
        spreadOne: true,
        elem: '.layui-side-scroll',
        url: '/static/js/nav.json'
    });
    // navbar.prototype.cleanCached();
    navbar.render();
    $('.layui-nav-item').click(function(event) {
        $(this).siblings().removeClass('layui-nav-itemed');
    });

    $('.layui-tab-title li').eq(0).find('i').remove();

    height = $('.layui-layout-admin .site-demo').height();
    $('.layui-layout-admin .site-demo').height(height-100);

    if($(window).width()<750){
        trun = 0;
        $('.x-slide_left').css('background-position','0px -61px');
    }else{
        trun = 1;
    }
    $('.x-slide_left').click(function(event) {
        if(trun){
            $('.x-side').animate({left: '-200px'},200).siblings('.x-main').animate({left: '0px'},200);
            $(this).css('background-position','0px -61px');
            trun=0;
        }else{
            $('.x-side').animate({left: '0px'},200).siblings('.x-main').animate({left: '200px'},200);
            $(this).css('background-position','0px 0px');
            trun=1;
        }

    });

    //监听导航点击
    element.on('nav(side)', function(elem){
        title = elem.find('cite').text();
        url = elem.find('a').attr('_href');
        for (var i = 0; i <$('.x-iframe').length; i++) {
            if($('.x-iframe').eq(i).attr('src')==url){
                element.tabChange('x-tab', $('.x-iframe').eq(i).attr('var'));
                return;
            }
        };
        navbarIndex++;
        element.tabAdd('x-tab', {
            title: title
            ,content: '<iframe frameborder="0" src="'+url+'" class="x-iframe" var="tab'+navbarIndex+'"></iframe>'
            ,id:'tab'+navbarIndex+''
        });
        element.tabChange('x-tab', 'tab'+navbarIndex);
    });
});
